(function () {
    $(document).ready(function () {
        // The only difference between an extension in a dashboard and an extension
        // running in a popup is that the popup extension must use the method
        // initializeDialogAsync instead of initializeAsync for initialization.
        // This has no affect on the development of the extension but is used internally.
        $('#wancheng').on('click',wanchenga);
        tableau.extensions.initializeDialogAsync().then(function (openPayload) {
            // alert(openPayload);
           var obj = JSON.parse(openPayload);
           $("#pdtb").val(obj["pdtb"]);
           $("#pdz").val(obj["pdz"]);
           $("#pdy").val(obj["pdy"]);
           $("#hangNums").val(obj["hangNums"]);
           $("#topNums").val(obj["topNums"]);
           $("#bjys").val(obj["bjys"]);
           $("#mbgzb").val(obj["mbgzb"]);
           $("#tpyj").val(obj["tpyj"]);
           $("#mbgzzd").val(obj["mbgzzd"]);
           $("#bjtpUrl").val(obj["bjtpUrl"]);
            $("#tpgd"+(obj["tpgd"]!=null?obj["tpgd"]:"0")).click();
        });
    });

})();

function wanchenga (){
    var obj = {};
    obj["pdtb"] =  $("#pdtb").val()?$("#pdtb").val():10;
    obj["pdz"] =  $("#pdz").val()?$("#pdz").val():10;
    obj["pdy"] =  $("#pdy").val()?$("#pdy").val():10;
    obj["hangNums"] =  $("#hangNums").val()?$("#hangNums").val():5;
    obj["topNums"] =  $("#topNums").val()?$("#topNums").val():5;
    obj["bjys"] =  $("#bjys").val()?$("#bjys").val():'#ffffff';
    obj["tpgd"] =  $('input:radio[name="tpgd"]:checked').val()!=null?$('input:radio[name="tpgd"]:checked').val():'0';
    obj["mbgzb"] =  $("#mbgzb").val()?$("#mbgzb").val():'';
    obj["tpyj"] =  $("#tpyj").val()?$("#tpyj").val():'';
    obj["mbgzzd"] =  $("#mbgzzd").val()?$("#mbgzzd").val():'Post thumbnail URL';
    obj["bjtpUrl"] =  $("#bjtpUrl").val()?$("#bjtpUrl").val():'../images/null_pic.png';

    tableau.extensions.settings.set("ImagePra", JSON.stringify(obj));
    tableau.extensions.settings.saveAsync().then((newSavedSettings) => {
        debugger;
        tableau.extensions.ui.closeDialog(JSON.stringify(obj));
    });
}
